﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CSKernelClient;
using CSReportDll;
using CSReportGlobals;

namespace CSReportEditor
{
    public static class cGlobals
    {

        public const String C_MODULE = "CSReportEditor.cGlobals";

        public const String C_KEY_HEADER = "RH";
        public const String C_KEY_FOOTER = "RF";
        public const String C_KEY_DETAIL = "RD";
        public const String C_KEY_GROUPH = "GH";
        public const String C_KEY_GROUPF = "GF";

        public const String c_BTN_PRINT        = "PRINT";
        public const String c_BTN_PROPERTIES   = "PROPERTIES";
        public const String c_BTN_DB           = "DB";
        public const String c_BTN_SAVE         = "SAVE";
        public const String c_BTN_OPEN         = "OPEN";
        public const String c_BTN_TOOL         = "TOOL";
        public const String c_BTN_NEW          = "NEW";
        public const String c_BTN_PREV         = "PREV";

        public const String c_BTN_ALIGN_LEFT   = "ALIGN_LEFT";
        public const String c_BTN_ALIGN_CENTER = "ALIGN_CENTER";
        public const String c_BTN_ALIGN_RIGHT  = "ALIGN_RIGHT";

        public const String c_BTN_CTL_ALIGN_TOP        = "CTL_ALIGN_TOP";
        public const String c_BTN_CTL_ALIGN_BOTTOM     = "CTL_ALIGN_BOTTOM";
        public const String c_BTN_CTL_ALIGN_VERTICAL   = "CTL_ALIGN_VERTICAL";
        public const String c_BTN_CTL_ALIGN_HORIZONTAL = "CTL_ALIGN_HORIZONTAL";
        public const String c_BTN_CTL_ALIGN_LEFT       = "CTL_ALIGN_LEFT";
        public const String c_BTN_CTL_ALIGN_RIGHT      = "CTL_ALIGN_RIGHT";

        public const String c_BTN_CTL_WIDTH  = "CTL_WIDTH";
        public const String c_BTN_CTL_HEIGHT = "CTL_HEIGHT";

        public const String C_CONTROL_NAME = "Control";

        public const int C_HEIGHT_NEW_SECTION = 23;
        public const int C_HEIGHT_BAR_SECTION = 8;

        public const int C_NO_CHANGE = -32768;

        public static void setStatus()
        { 
        
        }

        public static bool isNumberField(int fieldType)
        {
            return false;
        }

        public static bool showGroupProperties(cReportGroup group, cEditor f)
        {
            try
            {
                bool isNew = false;

                f.setShowingProperties(true);

                if (f.getFGroup() == null)
                {
                    f.setFGroup(new fGroup());
                }

                if (group == null)
                {
                    isNew = true;
                }

                CSMaskEdit.cMaskEdit txControl = null;

                txControl = f.getFGroup().getTxName();
                if (isNew)
                {
                    txControl.Text = "Group " + (f.getReport().getGroups().count() + 1).ToString();
                }
                else
                {
                    txControl.Text = group.getName();
                    txControl = f.getFGroup().getTxDbField();
                    txControl.Text = group.getFieldName();

                    if (group.getOderType() == csRptGrpOrderType.CSRPTGRPASC)
                    {
                        f.getFGroup().setAsc(true);
                    }
                    else
                    {
                        f.getFGroup().setDesc(true);
                    }
                    f.getFGroup().setPrintInNewPage(group.getPrintInNewPage());
                    f.getFGroup().setReprintGroup(group.getRePrintInNewPage());
                    f.getFGroup().setGrandTotal(group.getGrandTotalGroup());

                    switch (group.getComparisonType())
                    {
                        case csRptGrpComparisonType.CSRPTGRPDATE:
                            f.getFGroup().setSortByDate(true);
                            break;

                        case csRptGrpComparisonType.CSRPTGRPNUMBER:
                            f.getFGroup().setSortByNumber(true);
                            break;

                        case csRptGrpComparisonType.CSRPTGRPTEXT:
                            f.getFGroup().setSortByText(true);
                            break;
                    }
                }

                f.getFGroup().ShowDialog();

                if (f.getFGroup() == null)
                {
                    f.setShowingProperties(false);
                    return false;
                }
                if (!f.getFGroup().getOk())
                {
                    if (f.getFGroup() != null)
                    {
                        f.getFGroup().Close();
                        f.getFGroup().Dispose();
                        f.setFGroup(null);
                    }
                    f.setShowingProperties(false);
                    return false;
                }

                if (isNew)
                {
                    group = f.getReport().getGroups().add(null, "");
                }
                txControl = f.getFGroup().getTxName();
                group.setName(txControl.Text);
                txControl = f.getFGroup().getTxDbField();
                group.setFieldName(txControl.Text);

                group.setIndex(f.getReport().getGroups().count());
                group.setOderType(f.getFGroup().getAsc()
                                    ? csRptGrpOrderType.CSRPTGRPASC
                                    : csRptGrpOrderType.CSRPTGRPDESC);

                group.setPrintInNewPage(f.getFGroup().getPrintInNewPage());
                group.setRePrintInNewPage(f.getFGroup().getReprintGroup());
                group.setGrandTotalGroup(f.getFGroup().getGrandTotal());

                if (f.getFGroup().getSortByDate())
                {
                    group.setComparisonType(csRptGrpComparisonType.CSRPTGRPDATE);
                }
                else if (f.getFGroup().getSortByNumber())
                {
                    group.setComparisonType(csRptGrpComparisonType.CSRPTGRPNUMBER);
                }
                else if (f.getFGroup().getSortByText())
                {
                    group.setComparisonType(csRptGrpComparisonType.CSRPTGRPTEXT);
                }

                f.setShowingProperties(false);

                if (isNew)
                {
                    f.addSection(csRptTypeSection.CSRPTTPGROUPHEADER);
                    f.addSection(csRptTypeSection.CSRPTTPGROUPFOOTER);
                }

                f.setDataHasChanged(true);
                if (f.getFGroup() != null)
                {
                    f.getFGroup().Close();
                    f.getFGroup().Dispose();
                    f.setFGroup(null);
                }
                f.setShowingProperties(false);

                return true;

            }
            catch (Exception ex)
            {
                if (f.getFGroup() != null)
                {
                    f.getFGroup().Close();
                    f.getFGroup().Dispose();
                    f.setFGroup(null);
                }
                f.setShowingProperties(false);

                cError.mngError(ex, "ShowGroupProperties", C_MODULE, "");

                return false;
            }
        }

    }

    public enum CSRptEditorMoveType {
        CSRPTEDMOVTHORIZONTAL,
        CSRPTEDMOVTVERTICAL,
        CSRPTEDMOVTALL,
        CSRPTEDMOVLEFT,
        CSRPTEDMOVRIGHT,
        CSRPTEDMOVUP,
        CSRPTEDMOVDOWN,
        CSRPTEDMOVLEFTDOWN,
        CSRPTEDMOVLEFTUP,
        CSRPTEDMOVRIGHTDOWN,
        CSRPTEDMOVRIGHTUP,
        CSRPTEDMOVTNONE
    }

    public enum csRptEditCtrlType {
        CSRPTEDITNONE,
        CSRPTEDITLABEL,
        CSRPTEDITFIELD,
        CSRPTEDITFORMULA,
        CSRPTEDITIMAGE,
        CSRPTEDITCHART
    }

    public enum csESectionLineTypes
    {
        C_KEY_SECLN_HEADER = 1000,
        C_KEY_SECLN_DETAIL = 1001,
        C_KEY_SECLN_FOOTER = 1002,
        C_KEY_SECLN_GROUPH = 1003,
        C_KEY_SECLN_GROUPF = 1004
    }

}
